<%@page import="java.util.Iterator"%>
<%@page import="java.util.Collection"%>
<%@page import="javax.rmi.PortableRemoteObject"%>
<%@page import="manufacturerBean.ManufacturerHome"%>
<%@page import="manufacturerBean.Manufacturer"%>
<%@page import="categorybean.Category"%>
<%@page import="categorybean.CategoryHome"%>
<%@page import="GoodsBean.Goods"%>
<%@page import="GoodsBean.GoodsHome"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="java.util.Set"%>
<%@page import="java.util.HashMap"%>
<%@page import="DBConnection.ATeamObject"%>
<%@page import="javax.print.attribute.Size2DSyntax"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%><%-- 
    Document   : index
    Created on : 29.09.2011, 18:36:19
    Author     : X@KER
--%>


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>База данных интернет-магазина</title>
        <%  InitialContext initialContext;
            GoodsHome goodsHome;
            Goods goods;     
            Object homeObject;
            
            CategoryHome categoryHome;
            Category category;
            Object homeObject1;
            
            Manufacturer manufacturer;
            ManufacturerHome manufacturerHome;
            Object homeObject2;
            
            ATeamObject ato = new ATeamObject();
            
            try{
                initialContext = new InitialContext();
                homeObject = initialContext.lookup("GoodsBean");
                goodsHome = (GoodsHome) PortableRemoteObject.narrow(homeObject,
                        GoodsHome.class);
                
                homeObject1 = initialContext.lookup("CategoryBean");
                categoryHome = (CategoryHome) PortableRemoteObject.narrow(homeObject1,
                        CategoryHome.class);
                
                homeObject2 = initialContext.lookup("ManufacturerBean");
                manufacturerHome = (ManufacturerHome) PortableRemoteObject.narrow(homeObject2,
                        ManufacturerHome.class);
        %>
        <script lang="javascript">
            function confirmChoice(form,value){
                if(value==">") txt.style.visibility = "hidden";
                else if(value=="<")txt.style.visibility = "hidden";
                else if(value=="=")txt.style.visibility = "hidden";
                else if(value=="BETWEEN")txt.style.visibility = "visible";
            }
            function disable(){
                txt.style.visibility="hidden";
            }
        </script>   
    </head>    
    <body background="1.jpg" bgproperties="fixed" onload="disable()">        
    <center>
        <h1>База данных интернет-магазина</h1>
    </center>
    <p><a href="HelpPage.html">Помощь в навигации по сайту</a></p>
    <p><a href="Manufacturers.jsp">Список производителей</a></p>
    <p><a href="catalogues.jsp">Каталог товаров</a></p>
    <p><a href="allGoodsList.jsp">Все товары</a></p>

    <form name="MainPageForm" method="post" action="findResults.jsp">
        <center>
            <h2>Поиск товаров</h2>
            <table>
                <tr>
                    <td>
                        <b>Наименование товара</b>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="text" name="GoodsName" size="50">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="radio" name="SearchingCriteria" value="0" checked="true"> Совпадает
                    </td>
                </tr>
                <tr>
                    <td> 
                        <input type="radio" name="SearchingCriteria" value="1"> Содержит
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>Цена товара</b>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="text" name="GoodsPriceFrom" size="10">
                        <input type="text" name="GoodsPriceTo" size="10" id="txt">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="radio" name="GoodsPriceOptions" value=">" onclick="if(this.checked){confirmChoice(this.form,this.value);}"> Больше чем<br>
                        <input type="radio" name="GoodsPriceOptions" value="<" onclick="if(this.checked){confirmChoice(this.form,this.value);}"> Меньше чем<br>
                        <input type="radio" name="GoodsPriceOptions" value="=" checked="true" onclick="if(this.checked){confirmChoice(this.form,this.value);}"> Равно значению<br>
                        <input type="radio" name="GoodsPriceOptions" value="BETWEEN" onclick="if(this.checked){confirmChoice(this.form,this.value);}"> Лежит в диапазоне<br>
                    </td>
                </tr>
                <tr>
                    <td><b>Производитель</b><td>
                </tr>
                <%  Collection allManufacturer = manufacturerHome.findAll();
                    Iterator iter = allManufacturer.iterator();                    
                %>
                <tr>
                    <td>
                        <select name="ManufacturerSelect">
                            <option></option>
                            <% while(iter.hasNext()){
                                   manufacturer = (Manufacturer)iter.next();                       
                            %>
                                   <option value="<%= manufacturer.getObjectId() %>"><%= manufacturer.getName() %></option>
                            <% }%>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td><b>Категория товара</b></td>
                </tr>
                <% Collection allCategory = categoryHome.findAll();
                   iter = allCategory.iterator();    
                %>
                <tr>
                    <td>
                        <select name="GoodsCategorySelect">
                            <option></option>
                            <% while(iter.hasNext()){
                                   category = (Category) iter.next();
                            
                            %>
                                   <option value="<%= category.getObjectId() %>"><%= category.getName() %></option>
                            <% }%>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="submit" value="Поиск">
                        <input type="reset" value="Очистить">
                    </td>
                </tr> 
            </table>
        </center>
    </form>
    <% } catch(Exception e){
            e.printStackTrace(System.err);
       }
    %>
</body>
</html>
